package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;

import com.seanchenxi.gwt.wordpress.domain.model.Blog;
import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class BlogsResponseHandler extends BaseResponseHandler<ArrayList<Blog>>{

	@Override
	public ArrayList<Blog> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<Blog> blogs = new ArrayList<Blog>();
		for(Object obj : (ArrayList<?>)object){
			Blog blog = ModelFactory.ToBlog(obj);
			if(blog!=null && !blogs.contains(blog)){ 
				blogs.add(blog);
			}
		}
		
		return blogs;
	}
	
}
